
import requests
from bs4 import BeautifulSoup

def handler():
    # 调用图片生成接口
    url = "https://dashscope.aliyuncs.com/api/v1/services/aigc/text2image/image-synthesis"
    headers = {"X-DashScope-Async": "enable",
               "Authorization": "Bearer sk-c860168de7184769abd0b068a4486ad9",
               "Content-Type": "application/json'"}
    payload = {
        "model": "wanx2.1-t2i-turbo",
        "input": {
            "prompt": "一间有着精致窗户的花店，漂亮的木质门，摆放着花朵"
        },
        "parameters": {
            "size": "1024*1024",
            "n": 1
        }
    }
    response = requests.post(url, headers=headers, json=payload)
    print(response)

    if response.status_code == 200:
        data = response.json()
        print(data)
        taskId = data['output']['task_id']
        # requestId = data["message"]["request_id"]
        print(taskId)
    else:
        print("请求失败，状态码：", response.status_code)

    # 循环调用查询图片生成接口，如果生成图片则结束

    return {"message": taskId}

handler()
